class IntBuffer{
	private int index;
	private int[] buffer;
	
	public IntBuffer(){
		buffer = new int[8];
	}
	
	public synchronized void add(int num){
		// while(true){ // busy waiting w/out synchronized?
		while(index == buffer.length -1){	
			// if( index < buffer.length ){
			try{
				wait();	
			}
			catch(InterruptedException e){
			}
		}				
			// }
		buffer[index++] = num;
		notifyAll();
		// return;
	}
	
	public synchronized int remove(){
		// while(true){
		while(index == 0){	
			// if(index > 0){
				// return buffer[--index];
			// }
			try{
				wait();
			} catch(InterruptedException e){
			}
		}
		int ret = buffer[--index];
		notifyAll();
		return ret;
	}
	
}